<template>
    <div class="driver-model">
        <lar-ui-plane>
            <div class="driver-type">
                <el-radio-group v-model="driverType">
                    <el-radio-button label="1">司机位置</el-radio-button>
                    <el-radio-button label="2">位置地图</el-radio-button>
                </el-radio-group>
            </div>
            <lar-table model="user.driver" canAdd="canAdd" v-if="driverType === '1'"></lar-table>
            <div :loading="loading" v-if="driverType === '2'">
                <lar-map-driverposition  style="margin:0 -20px -20px"/>
            </div>
        </lar-ui-plane>
    </div>

</template>
<script>
    export default {
        data() {
            return {
                driverType: '1',
                loading: false
            }
        },
        watch: {
            driverType:function (val) {
                if (val == '2') {
                    // this.getDriverData();
                }
            }
        },
        methods: {
            getDriverData() {
                this.loading = true;
                let query = {};
                this.$http.get(this.$larfree.httpQuery(query, 'common/user/driver'))
                    .then((res) => {
                        this.loading = false;
                        this.dispatchObj.driverData.driverList = [];
                        this.dispatchObj.driverData.taskNowEndLngLat = [];
                        this.dispatchObj.driverData.driverNowTask = [];
                        let nowTime = (new Date()).getTime();
                        res.data.data.forEach(item => {
                            let line = [];
                            item['nowTime'] = nowTime;
                            if (item.lon && item.lat) {
                                this.dispatchObj.driverData.driverList.push(item);
                            } else {
                                item.lon = '137.3730468750'; // 没有经纬度先默认
                                item.lat = '25.9975499196';
                                this.dispatchObj.driverData.driverList.push(item);
                            }
                            let lines = {};
                            if ( item.current_mission_destination !== null ) {
                                line = [[item.lon,item.lat],[item.current_mission_destination.end_lon, item.current_mission_destination.end_lat]];
                                this.dispatchObj.driverData.taskNowEndLngLat.push({
                                    id: item.id,
                                    path: [item.current_mission_destination.end_lon, item.current_mission_destination.end_lat],
                                    driverName: item.name,
                                    events: {
                                        click: () => {
                                            this.$router.push({path:'/dialog/show/express.mission/' + item.current_mission_destination.id})
                                        }
                                    }
                                });
                                lines = {
                                    id:item.id,
                                    path: line
                                }

                            }
                            this.dispatchObj.driverData.driverNowTask.push(lines);
                        });

                    })
                    .catch((error) => {
                        this.loading = false;
                        if (error.response.data.msg) {
                            this.$message.error(error.response.data.msg);
                        } else {
                            this.$message.error('请求错误：' + error.response.status);
                        }
                    });
            },
        }

    }


</script>
<style lang="less" scoped>
  .driver-model{
      .driver-type{
          padding: 0 0 20px 0;
      }
  }
</style>

